"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/6/11 14:10
@Description : 
 pymysql 实现数据的增删改操作
"""
import pymysql
from pymysql.cursors import DictCursor

mysql_connection = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='root',
    db='python2512',
    autocommit=True,  # 自动提交事务
    cursorclass=DictCursor  # 字典格式的游标
)
# 设置获取游标的格式  字典格式的游标  {}
# cursor = mysql_connection.cursor(cursor=DictCursor)
cursor = mysql_connection.cursor()
str_sql = "insert into user (username, password) values (%(username)s, %(password)s)"
cursor.execute(str_sql,{'username':'admin','password':'111111'})

# 释放资源
cursor.close()
mysql_connection.close()
